package com.world.tg.controller;

import com.world.tg.result.JsonResult;
import com.world.tg.service.DetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/detail")
@Api(tags = "商品详情模块")
@CrossOrigin("*")
public class DetailController {

    @Autowired
    DetailService detailService;

    @GetMapping("/byBid")
    @ApiOperation("根据ID查询商品")
    @ApiImplicitParam(name = "bid",value = "书籍ID",required = true,paramType = "query")
    public JsonResult findBook(@RequestParam Integer bid, HttpServletRequest request){
        System.out.println(request.getHeader("xxx"));
        return detailService.findBookByBid(bid);
    }

    @GetMapping("/seller")
    @ApiOperation("查询商家")
    @ApiImplicitParam(name = "sid",value = "商家ID",required = true,paramType = "query")
    public JsonResult findSeller(@RequestParam Integer sid){
        return detailService.findSeller(sid);
    }

    @GetMapping("/comment")
    @ApiOperation("查询评论")
    @ApiImplicitParam(name = "bid",value = "书籍ID",required = true,paramType = "query")
    public JsonResult findComment(@RequestParam Integer bid){
        return detailService.findComment(bid);
    }

    @GetMapping("/bookParam")
    @ApiOperation("书籍参数")
    @ApiImplicitParam(name = "bid",value = "书籍ID",required = true,paramType = "query")
    public JsonResult findBookParam(@RequestParam Integer bid){
        return detailService.findBookParam(bid);
    }
}
